<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
 require_once( BASEPATH.'smarty/libs/Smarty.class.php' );

class MySmarty extends Smarty {
    public  $_layout = 'default.phtml';
    public $layout_dir=null;
    function __construct(){
        parent::__construct();
        $this->layout_dir=APPPATH . "layouts/";
        @require WEBROOTPATH."/inc/"."config.php"; 
        $this->compile_dir = APPPATH . "views/templates_c/";
        $this->template_dir = APPPATH . "views/templates/";
        $this->cache_dir=APPPATH."cache/";
        $this->caching=($webdb['webcache']=='1')?True:False;
        $this->cache_lifetime =60*(float)($webdb['webcache_lifetime']); 
        $this->left_delimiter    = '{';
        $this->right_delimiter    = '}';       
      if(!is_dir($this->compile_dir)){
        mkdir($this->compile_dir, 0777);
      }
      if($this->caching && !is_dir($this->cache_dir)){
        mkdir($this->cache_dir, 0777);
      }
        $ci =& get_instance();
        $this->assign( 'APPPATH', APPPATH );
        $this->assign( 'BASEPATH', BASEPATH );
		$this->assign( 'WEBURL', $ci->config->item('base_url') );
        // Assign CodeIgniter object by reference to CI
        if ( method_exists( $this, 'assignByRef') ){
            $ci =& get_instance();
            $this->assignByRef("ci", $ci);
        }
        log_message('debug', "Smarty Class Initialized");
        
     
    }

   public  function display($tpl='',$filenName='',$title='',$keywords='',$description='',$layout=null){
       if($layout=='home'){
           $mainTpl=$tpl;
       }elseif($layout==null){
           $mainTpl=$this->layout_dir.$this->_layout;
       }else{
           $mainTpl=$this->layout_dir.$layout;
       }
       $this->assign('file_tpl', $tpl);
       $this->assign('webtitle',$title);
       $this->assign('webkeywords',$keywords);
       $this->assign('webdescription',$description);
       parent::display($mainTpl, $filenName);
   }
}
